package com.hyh.capture;

import android.graphics.ImageFormat;
import android.hardware.Camera;
import android.util.Log;
import android.view.SurfaceHolder;

import java.io.IOException;
import java.util.List;

/**
 * Created by Administrator on 2019/1/22.
 */

public class CameraUtil implements Camera.PreviewCallback {

    Camera camera;
    public CameraUtil(SurfaceHolder surfaceHolder){
        try {
            camera = Camera.open(Camera.CameraInfo.CAMERA_FACING_FRONT);
            camera.setPreviewDisplay(surfaceHolder);
            Camera.Parameters parameters = camera.getParameters();
//            parameters.setPreviewSize(640,480);
//            parameters.setPreviewFormat(ImageFormat.NV21);
//            parameters.setRotation(90);
//            camera.setParameters(parameters);
            camera.setDisplayOrientation(90);
            camera.setPreviewCallback(this);
            List<Camera.Size> sizes =  parameters.getSupportedPictureSizes();
            for(Camera.Size mySize:sizes){
                Log.e("androidLog",mySize.width+":"+mySize.height);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void startPreview(){
        camera.startPreview();
    }

    @Override
    public void onPreviewFrame(byte[] data, Camera camera) {

    }
}
